//
//  RCServerNoticeVC.m
//  RocketProject
//
//  Created by chen jiedan on 13-10-3.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCServerNoticeVC.h"
#import "CommonDefines.h"
#import "UIColor-Expanded.h"
#import "IManager+RequestServerDetailInfo.h"
#import "AppDelegate.h"
#import "RCBaseServerDataModel.h"

@interface RCServerNoticeVC ()<IManagerDelegate>{
    UILabel *nameLabel;
    UILabel *phoneLabel;
    UITextView *inputField;
    
    int64_t _reqID;
    
    BOOL _isRealOrder;
}

@property (nonatomic, copy) NSString *orderID;
@property (nonatomic, copy) NSString *userName;
@property (nonatomic, copy) NSString *phoneNum;
@end

@implementation RCServerNoticeVC
@synthesize orderID  = _orderID;
@synthesize userName = _userName;
@synthesize phoneNum = _phoneNum;

- (void) dealloc
{
    [[IManager sharedInstance] cancelFetchDataRequestByRequestID:_reqID];
    [_orderID release];
    [_phoneNum release];
    [_userName release];
    [super dealloc];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (id) initWithUserName:(NSString *)userName withPhone:(NSString *)phone withOrderID:(NSString *)orderID withIsOrder:(BOOL)isRealOrder
{
    if (self) {
        self.orderID = orderID;
        self.phoneNum = phone;
        self.userName = userName;
        _isRealOrder = isRealOrder;
    }
    return self;
    
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.titleLabelText = @"通知客户";
    self.navigationItem.titleView = [self createTitleView];
    
    nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 15, 230, 15)];
    nameLabel.backgroundColor = [UIColor clearColor];
    nameLabel.textColor = kNormalTextColor;
    nameLabel.text = [NSString stringWithFormat:@"姓名：%@",self.userName];
    nameLabel.font = [UIFont fontWithName:kFontNameHelvetica size:15];
    [self.viewContainer addSubview:nameLabel];
    [nameLabel release];
    
    
    
    phoneLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 35, 260, 15)];
    phoneLabel.backgroundColor = [UIColor clearColor];
    phoneLabel.textColor = kNormalTextColor;
    phoneLabel.font = [UIFont fontWithName:kFontNameHelvetica size:15];
    phoneLabel.text = [NSString stringWithFormat:@"手机：%@",self.phoneNum];
    [self.viewContainer addSubview:phoneLabel];
    [phoneLabel release];
    
    
    UILabel *msgLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 55, 110, 15)];
    msgLabel.backgroundColor = [UIColor clearColor];
    msgLabel.textColor = kNormalTextColor;
    msgLabel.font = [UIFont fontWithName:kFontNameHelvetica size:15];
    msgLabel.text = @"短信内容：";
    [self.viewContainer addSubview:msgLabel];
    [msgLabel release];
    
    inputField = [[UITextView alloc] initWithFrame:CGRectMake(90, 55, 210, 165)];
    [self.viewContainer addSubview:inputField];
    [inputField release];
    
    
    UIButton  *submitBtn = [[UIButton alloc] initWithFrame:CGRectMake(14, 230, 320-28, 40)];
    [submitBtn setTitle:@"提交" forState:UIControlStateNormal];
    [self.viewContainer addSubview:submitBtn];
    UIImage *loginIMG = [UIImage imageNamed:@"login_btn"];
    [submitBtn setBackgroundImage:loginIMG forState:UIControlStateNormal];
    [submitBtn addTarget:self action:@selector(submitPress) forControlEvents:UIControlEventTouchUpInside];
    [submitBtn release];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void) submitPress
{
    [[IManager sharedInstance] cancelFetchDataRequestByRequestID:_reqID];
    _reqID = [[IManager sharedInstance] requestPostOrderInfo:self.orderID withIsOrder:_isRealOrder withUser:self.userName withPhone:self.phoneNum withContent:inputField.text withDelegate:self];
//   _reqID =  [[IManager sharedInstance] requestPostOrderInfo:self.orderID withUser:self.userName withPhone:self.phoneNum withContent:inputField.text withDelegate:self];
    
}


- (void) updateViewForError:(NSError *)errorInfo withRequestId:(int64_t)requestId
{
    [RCAppDelegate alertWithCustomizeString:@"提交失败"];
}

- (void) updateViewForSuccess:(IDataModel *)dataModel withRequestId:(int64_t)requestId
{
    if (dataModel.errorNO == RCErrorTypeNoError) {
        [RCAppDelegate alertWithCustomizeString:@"通知成功"];
        [self.navigationController popViewControllerAnimated:YES];
    }else{
        [RCAppDelegate alertWithCustomizeString:dataModel.errorMsg];

    }

}

@end
